<template>
	<view class="container">
		<view class="topbox flex">
			<image class="pic" :src="orderinfo.pic" mode=""></image>
			<view class="proinfo flex">
				<view class="name">
					{{orderinfo.p_name}}
				</view>
				<view class="addr">
					{{orderinfo.address}}
				</view>
				<view class="infobottom flex">
					<view class="num">
						数量×{{orderinfo.num||0}}
					</view>
					<view class="price">
						￥{{orderinfo.price||0}}
					</view>
				</view>
			</view>
		</view>
		<view class="smbox flex">
			<image class="smicon" src="/pages/tongz/static/zs.png" mode=""></image>
			今日通政参考价值1通政等于{{refer||0}}元
		</view>
		<view class="conbox">
			<view class="conitem flex">
				<view class="item_left">
					让利百分比
				</view>
				<view class="itemright flex">
					<input type="number" style="text-align: right;color: #FE712A;" v-model='form.bili'
						@input="form.value=((form.bili*orderinfo.price/100) /refer ).toFixed(8)">
					<view class="right_left cFE7">
						%
					</view>
					<image class="icon" src="/static/img/home/more.png" mode=""></image>
				</view>
			</view>
			<view class="conitem flex">
				<view class="item_left">
					下单时间
				</view>
				<view class="itemright flex">
					<view class="right_left">
						{{$u.timeFormat(orderinfo.createtime, 'yyyy-mm-dd hh:MM')}}
						<!-- {{orderinfo.createtime}} -->
					</view>
					<image class="icon" src="/static/img/home/more.png" mode=""></image>
				</view>
			</view>
			<view class="conitem flex">
				<view class="item_left">
					当前状态
				</view>
				<view class="itemright flex">
					<!-- <view class="right_left cFE7">
						已发货
					</view> -->
					<view class="right_left cFE7" v-if="form.status==1">
						待发货
					</view>
					<view class="right_left cFE7" v-if="form.status==2">
						已发货
					</view>
					<view class="right_left cFE7" v-if="form.status==3">
						已完成
					</view>
					<image class="icon" src="/static/img/home/more.png" mode=""></image>
				</view>
			</view>
			<view class="conitem flex">
				<view class="item_left">
					让利通政
				</view>
				<view class="itemright flex">
					<view class="right_left cFE7">
						{{form.value}}
					</view>
					<image class="icon" src="/static/img/home/more.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="btn" @click="submit">
				确认让利
			</view>
		</view>
	</view>
</template>

<script>
	import {
		orderDetail,getproductscore
	} from '@/api/product.js'
	import {
		submitScoreA
	} from '@/api/integral.js'
	export default {
		data() {
			return {
				orderinfo: {},
				form: {
					product_id: '',
					our_product_id: '',
					status: "",
					bili: 5,
					value: ''
				},
				refer:0
			};
		},
		onLoad(option) {
			this.form.product_id = option.product_id
			this.form.our_product_id = option.our_product_id
			this.form.status = option.status
			this.refer = option.refer
			
			orderDetail({
				orderid: this.form.our_product_id
			}).then(res => {
				this.orderinfo = res.data.data.list
				this.form.value = ((this.form.bili * this.orderinfo.price / 100 ) /this.refer ).toFixed(8)
				this.orderinfo.pic = this.$BASE_URL + this.orderinfo.p_image.split(',')[0]
			})
			
		},
		methods: {
			submit() {
				// console.log(this.form.bili)
				if (this.form.bili < 5 || this.form.bili > 95) {
					uni.showToast({
						title: '让利百分比最低不能低于百分之五。最高不能超过百分之九十',
						icon: 'none',
						duration: 2000
					})
					return
				}
				submitScoreA(this.form).then(res => {
					// console.log(res)
					if (res.data.code == 1) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.container {
		padding: 40rpx 30rpx;

		.topbox {
			background: #FFFFFF;
			box-shadow: 0px 1rpx 24rpx 0px rgba(24, 24, 24, 0.08);
			border-radius: 25rpx;
			padding: 36rpx 24rpx;

			.pic {
				width: 140rpx;
				height: 140rpx;
				border-radius: 8rpx;
			}

			.proinfo {
				height: 140rpx;
				flex-direction: column;
				justify-content: space-between;
				align-items: flex-start;
				flex: 1;
				margin-left: 27rpx;

				.name {
					color: #333333;
					font-size: 32rpx;
					font-weight: bold;
				}

				.addr {
					color: #6A6A6A;
					font-size: 24rpx;
				}

				.infobottom {
					justify-content: space-between;
					width: 100%;

					.num {
						color: #6A6A6A;
						font-size: 24rpx;
					}

					.price {
						color: #F85707;
						font-size: 36rpx;
						font-weight: bold;
						margin-right: 30rpx;
					}
				}
			}
		}

		.smbox {
			margin-top: 25rpx;
			height: 92rpx;
			background: #FE712A;
			box-shadow: 0px 1rpx 24rpx 0px rgba(24, 24, 24, 0.08);
			border-radius: 25rpx;
			color: #fff;
			font-size: 26rpx;
			// font-weight: bold;
			padding: 0 24rpx;

			.smicon {
				width: 43rpx;
				height: 39rpx;
				margin-right: 14rpx;
			}
		}

		.conbox {
			border-top: 1rpx solid #F5F5F5;
			margin-top: 14rpx;

			.conitem {
				justify-content: space-between;
				padding: 35rpx 0;
				border-bottom: 1rpx solid #F5F5F5;

				.item_left {
					color: #333333;
					font-size: 32rpx;
				}

				.itemright {

					.right_left {
						font-size: 28rpx;
						margin-right: 30rpx;
						color: #333333;
					}

					.icon {
						width: 14rpx;
						height: 26rpx;
					}

					.cFE7 {
						color: #FE712A;
					}
				}
			}
		}

		.footer {
			position: fixed;
			bottom: 80rpx;
		}

		.btn {

			width: 687rpx;
			line-height: 114rpx;
			background: linear-gradient(153deg, #FF8717, #FF5F00);
			border-radius: 57rpx;
			text-align: center;
			font-size: 36rpx;
			color: #fff;
		}
	}
</style>
